/*
Copyright To change this template, choose Tools | Templates
Copyright and open the template in the editor.
 */
package com.click.app.model;

import com.click.app.Functions;
import com.click.app.util.Utilities;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * @author Joel Chuca Condo
 * @date 07/04/2009
 */
@Entity
@Table(name = "purchase_payments")
public class PurchasePayment extends BaseObject {

    private Long id;
    private Purchase purchase;
    private Double amount;
    private Double incrementAmount;
    private Date date;
    private String code;
    private Double amountLeft;
    private String observation;
    private Integer typePayment; // 0 normal payment ; 1 descount payment ; 2 fail payment ; 3 increment ; 4 increment discount

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id_purchase_payment", unique = true, nullable = false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_purchase")
    public Purchase getPurchase() {
        return this.purchase;
    }

    public void setPurchase(Purchase purchase) {
        this.purchase = purchase;
    }

    @Column(name = "amount", precision = 12, scale = 0)
    public Double getAmount() {
        return Functions.getDouble3Decimal(this.amount);
    }

    public void setAmount(Double amount) {
        this.amount = Functions.getDouble3Decimal(amount);
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "date", length = 10)
    public Date getDate() {
        return this.date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Column(name = "code", length = 50)
    public String getCode() {
        return code;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PurchasePayment)) {
            return false;
        }
        PurchasePayment other = (PurchasePayment) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append(this.getId()).append(this.amount).append(this.date).append(this.code).append(this.amountLeft).append(this.observation).toString();

    }

    @Column(name = "amount_left", precision = 12, scale = 0)
    public Double getAmountLeft() {
        return Functions.getDouble3Decimal(this.amountLeft);
    }

    /**
     * @param amountLeft the amountLeft to set
     */
    public void setAmountLeft(Double amountLeft) {
        this.amountLeft = Functions.getDouble3Decimal(amountLeft);
    }

    @Column(name = "observation", length = 255)
    public String getObservation() {
        if (observation == null) {
            observation = "-";
        }
        return observation;
    }

    public void setObservation(String observation) {
        this.observation = observation;
    }

    @Column(name = "type_payment")
    public Integer getTypePayment() {
        return typePayment;
    }

    public void setTypePayment(Integer typePayment) {
        this.typePayment = typePayment;
    }

    @Column(name = "increment_amount")
    public Double getIncrementAmount() {
        return Functions.getDouble3Decimal(incrementAmount);
    }

    public void setIncrementAmount(Double incrementAmount) {
        this.incrementAmount = Functions.getDouble3Decimal(incrementAmount);
    }

    @Transient
    public String getDateFormatted() {
        System.out.println("printing date formatted...");
        return Utilities.convertDate(date);
    }
}
